/**
 * @file   test_mutex002.c
 * @brief	Test mutex on two system tasks.
 * Expected result: 0101...
 */
#include "../header/common.h"
#include "../header/os.h"
#include "../header/uart.h"
#include "../header/trace.h"

#ifdef test_mutex002

enum { A=1, B};
const unsigned char PPP[] = {};
const unsigned int PT = 0;
EVENT* print_event;
MUTEX* mutex;
extern uint16_t trace_counter;

void generic_task(void)
{
	int arg = 0;
	arg = Task_GetArg();

    for(;;)
    {
        Mutex_Lock(mutex, 1);
        add_to_trace(arg);
        Mutex_Unlock(mutex);
    	Task_Next();
    }
}

int main(void) {
	UART_BPS bitrate = UART_38400;
	uart_init(bitrate);

    print_event = Event_Init();
    mutex = Mutex_Init();

    Task_Create(generic_task, 0, SYSTEM, 2);
    Task_Create(generic_task, 1, SYSTEM, 2);

    Event_Wait(print_event);
    print_trace();
    return 0;
}

#endif
